<%--
  Created by IntelliJ IDEA.
  User: yangtao
  Date: 2021-11-25
  Time: 22:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="app-title">
    <div>
        <h1><i class="fa fa-pie-chart"></i> 员工管理</h1>
    </div>
    <ul class="app-breadcrumb breadcrumb">
        <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
        <li class="breadcrumb-item"><a href="#">数据管理</a></li>
        <li class="breadcrumb-item"><a href="#">员工管理</a></li>
    </ul>
</div>

<div id="content" class="tile">
</div>

<script type="text/javascript">
    function showModal() {
        swal({
            title: "请填写必填信息！",
            text: '带' + '<label class="xrequired"></label>' + '为必填项，请按照要求填写井的信息！',
            html: true,
            type: "warning",
            showCancelButton: false,
            confirmButtonText: "确认",
            closeOnConfirm: false
        });
    }

    //加载table
    function loadTable(num) {
        if (typeof (num) == "undefined") {
            var num = 1;
        }
        $("#content").load("${ctx}/staff_list?page=" + num);
    }

    loadTable();

    function addStaff() {
        swal({
            title: "",
            text: '<div><form><div class="form-group"><label class="xrequired">员工姓名</label><input class="form-control" id="staffName" type="text" placeholder="请输入员工姓名"></div><div class="form-group"><label class="xrequired">所属部门</label> <input class="form-control" id="staffDep" type="text"placeholder="请输入所属部门"> </div> </form> </div>',
            showCancelButton: true,
            html: true,
            closeOnConfirm: true,
            showLoaderOnConfirm: true,
            type: "input",
            inputPlaceholder: "请输入员工姓名",
            imageUrl: "${ctx}/static/images/staff.png"
        }, function () {
            $.ajax({
                type: "post",
                url: "/staff_add",
                traditional: true,
                dataType: "text",
                data: {"name": $("#staffName").val(), "dep": $("#staffDep").val()},
                success: function (result) {
                    $("#content").html(result);
                },
                error: function (result) {

                }
            });
        });
    }

    function deleteStaff(pkId) {
        $("#overlay").css("display", "");
        $.ajax({
            type: "get",
            url: "/staff_delete",
            dataType: "text",
            data: {"pkId": pkId},
            success: function (result) {
                $("#content").html(result);
                $("#overlay").css("display", "none");
            }
        })
    }

    function toUpdate(pkId, name, dep) {
        alert(name + dep);
        swal({
            title: "",
            text: '<div><form><div class="form-group"><label class="xrequired">员工姓名</label><input class="form-control" id="staffName" type="text"></div><div class="form-group"><label class="xrequired">所属部门</label> <input class="form-control" id="staffDep" type="text" placeholder=' + dep + '> </div> </form> </div>',
            showCancelButton: true,
            html: true,
            closeOnConfirm: true,
            showLoaderOnConfirm: true,
            type: "input",
            inputPlaceholder: name,
            imageUrl: "${ctx}/static/images/staff.png"
        }, function () {
            sn = $("#staffName").val();
            sd = $("#staffDep").val();
            if (!isEmpty(sn)) {
                name = sn;
            }
            if (!isEmpty(sd)) {
                dep = sd;
            }
            if (!isEmpty(sn) || !isEmpty(sd)) {
                $.ajax({
                    type: "post",
                    url: "/staff_add",
                    traditional: true,
                    dataType: "text",
                    data: {"pkId": pkId, "name": name, "dep": dep},
                    success: function (result) {
                        $("#content").html(result);
                    },
                    error: function (result) {

                    }
                });
            }
        });
    }

    function isEmpty(obj) {
        if (typeof obj === 'undefined' || obj == null || obj === '') {
            return true;
        } else {
            return false;
        }
    }

</script>